package guanli;

import javax.swing.*;
import java.awt.*;

public class AdminPanel extends JPanel {
    private CardLayout cardLayout;
    private JPanel contentPanel;

    public AdminPanel() {
        setLayout(new BorderLayout());

        JLabel title = new JLabel("管理员功能模块", SwingConstants.CENTER);
        title.setFont(new Font("微软雅黑", Font.BOLD, 24));
        title.setBorder(BorderFactory.createEmptyBorder(20, 0, 10, 0));
        add(title, BorderLayout.NORTH);

        // 菜单按钮面板（多行）
        JPanel menuPanel = new JPanel(new GridLayout(2, 4, 10, 10));
        menuPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        // 七个功能按钮
        JButton btnRegister = new JButton("注册角色");
        JButton btnLockerManage = new JButton("柜体信息管理");
        JButton btnCourierManage = new JButton("快递员管理");
        JButton btnRepairerManage = new JButton("维修人员管理");

        JButton btnAdminManage = new JButton("管理员管理");
        JButton btnSendExpressManage = new JButton("寄件表单管理");
        JButton btnParcelManage = new JButton("包裹柜内管理");

        // 按钮事件绑定卡片名
        btnRegister.addActionListener(e -> cardLayout.show(contentPanel, "register"));
        btnLockerManage.addActionListener(e -> cardLayout.show(contentPanel, "locker"));
        btnCourierManage.addActionListener(e -> cardLayout.show(contentPanel, "courier"));
        btnRepairerManage.addActionListener(e -> cardLayout.show(contentPanel, "repairer"));

        btnAdminManage.addActionListener(e -> cardLayout.show(contentPanel, "adminManage"));
        btnSendExpressManage.addActionListener(e -> cardLayout.show(contentPanel, "sendExpress"));
        btnParcelManage.addActionListener(e -> cardLayout.show(contentPanel, "parcelManage"));

        // 加入菜单按钮
        menuPanel.add(btnRegister);
        menuPanel.add(btnLockerManage);
        menuPanel.add(btnCourierManage);
        menuPanel.add(btnRepairerManage);
        menuPanel.add(btnAdminManage);
        menuPanel.add(btnSendExpressManage);
        menuPanel.add(btnParcelManage);

        add(menuPanel, BorderLayout.SOUTH);

        // 中间卡片区域
        contentPanel = new JPanel();
        cardLayout = new CardLayout();
        contentPanel.setLayout(cardLayout);

        // 添加各子面板
        contentPanel.add(new RegisterUserPanel(), "register");
        contentPanel.add(new LockerManagePanel(), "locker");
        contentPanel.add(new UserManagePanel("快递员"), "courier");
        contentPanel.add(new UserManagePanel("维修人员"), "repairer");

        // ✅ 这里替换为新版 AdminManagePanel（含验证码认证）
        contentPanel.add(new AdminManagePanel(), "adminManage");

        contentPanel.add(new SendExpressManagePanel(), "sendExpress");
        contentPanel.add(new ParcelManagePanel(), "parcelManage");

        add(contentPanel, BorderLayout.CENTER);
    }
}
